package com.example.gpt;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class QianWenService {

    @Value("${qianwen.api.key}")
    private String apiKey;
    @Value("${qianwen.api.endpoint}")
    private String endpoint;

    public String callQianWen(String query) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);

        // 根据实际API要求构造请求体，此处假设是JSON格式
        String requestBody = "{\"query\": \"" + query + "\"}";
        HttpEntity<String> entity = new HttpEntity<>(requestBody, headers);

        RestTemplate restTemplate = new RestTemplate();
        String result = restTemplate.postForObject(endpoint, entity, String.class);

        return result;
    }
}